#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	string s1;
	cin >> s1;
	int n = s1.size();
	int a = 0;
	int b = 0;
	for (int i = 0; i <n; i++)
	{
		if (s1[i] == '1' && (i+1)%2!=0) a++;
		if (s1[i] == '1' && (i+1)%2==0) b++;
		if ((i + 1) & 1)
		{
			int c = (n - i - 1) / 2;
			int d = (n - i - 1) % 2;
			if (a > b + c + d)
			{
				pd(i + 1); puts(""); return;
			}
			if (b > a + c)
			{
				pd(i + 1); puts(""); return;
			}
		}
		else
		{
			int c = (n - i - 1) / 2;
			int d = (n - i - 1) % 2;
			if (a > b + c)
			{
				pd(i + 1); puts(""); return;
			}
			if (b > a + c + d)
			{
				pd(i + 1); puts(""); return;
			}
		}
	}
	puts("-1");

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}